package com.gillion.tms.entity;

import com.gfa4j.security.data.entity.AclMode;
import com.gfa4j.security.data.entity.IDataPermission;
import com.gfa4j.security.data.entity.ITable;

import com.gillion.business.model.SysAclTable;
import com.google.common.collect.Lists;

import java.util.Collection;

/**
 * Created by wengms on 2015/4/21.
 */
public class Table implements ITable{

    private String tableName;
    private AclMode aclMode;
    private Collection<IDataPermission> dataPermissions;

    public Table(SysAclTable table){
        this.tableName = table.getTableName();
        switch (table.getAclMode().intValue()){
            case 0:
                aclMode = AclMode.WIHTE_LIST;
                break;
            case 1:
                aclMode = AclMode.BLACK_LIST;
                break;
        }
    }


    public void setDataPermissions(Collection<IDataPermission> dataPermissions) {
        this.dataPermissions = dataPermissions;
    }

    @Override
    public String getTableName() {
        return this.tableName;
    }

    @Override
    public AclMode getAclMode() {
        return this.aclMode;
    }

    @Override
    public Collection<IDataPermission> getDataPermisssions() {
        if (this.dataPermissions == null){
            this.dataPermissions = Lists.newArrayList();
        }
        return this.dataPermissions;
    }
}
